﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ResxCrunch
{
    /// <summary>
    /// Find form class
    /// </summary>
    public partial class FrmFind : Form
    {
        #region Attributes
        private List<string> findStringHistory = new List<string>();
        #endregion Attributes

        #region Properties
        /// <summary>
        /// Gets or sets the find string.
        /// </summary>
        /// <value>The find string.</value>
        public List<string> FindStringHistory
        {
            get
            {
                return findStringHistory;
            }

            set
            {
                findStringHistory = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether search should go in the up direction.
        /// </summary>
        /// <value><c>true</c> if search should go in the up direction otherwise, <c>false</c>.</value>
        public bool SearchUp
        {
            get
            {
                return chkSearchUp.Checked;
            }

            set
            {
                chkSearchUp.Checked = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the search should be case sensitive.
        /// </summary>
        /// <value><c>true</c> if search should be case sensitive; otherwise, <c>false</c>.</value>
        public bool MatchCase
        {
            get
            {
                return chkMatchCase.Checked;
            }

            set
            {
                chkMatchCase.Checked = value;
            }
        }

        /// <summary>
        /// Gets or sets the find expression.
        /// </summary>
        /// <value>The find expression.</value>
        public string FindExpression
        {
            get
            {
                return comboFindTerm.Text;
            }

            set
            {
                comboFindTerm.Text = value;
            }
        }
        #endregion Properties

        #region Initialization
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmFind"/> class.
        /// </summary>
        public FrmFind()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Load event of the FrmFind control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrmFind_Load(object sender, EventArgs e)
        {
            if (FindStringHistory.Count > 0)
            {
                comboFindTerm.Items.AddRange(FindStringHistory.ToArray());
                comboFindTerm.SelectedIndex = 0;
            }
        }
        #endregion Initialization

        #region Events
        /// <summary>
        /// Handles the Click event of the btnFind control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnFind_Click(object sender, EventArgs e)
        {
            if (comboFindTerm.Text.Length > 0)
            {
                errorProviderFind.SetError(comboFindTerm, "");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                errorProviderFind.SetError(comboFindTerm, "Please enter a search criteria.");
                comboFindTerm.Focus();
            }
        }
        #endregion Events
    }
}
